package view;

import java.awt.BorderLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import controller.ByGroupController;
import controller.ByNameController;
import model.Contact;



/**
 * Main window of the application
 * 
 * The variables StaticSearch and StaticWord takes the values of the last type of search 
 * (by group, by name, by last added or normal = clean)
 *  and the value of the text the is entered by the suer in the search field
 *  to display the right list according to the choice of the user.
 *  
 * The variable StaticWord save the string the user typed for the search.
 * The variable StaticSearch save the type of search (by name, group, etc...).
 * 
 * @author Marie Morin
 *
 */
public class MainWindow extends JFrame{
	
	// The value of staticSearch depend on what type of research the user as done (by name, by group, by date, etc..)
	private String staticSearch ="clear";
	// The value of staticSearch depend on what word  the user was searching for
	private String staticWord ="";



/**
 * Constructor of the main window
 */
	public MainWindow() 
	{	
		this.Init();

	}
	

	
	/**
	 * Initialize the parameters of the window
	 */
	
	public void Init()
	{
		// Create the base window of the Address Book
				this.setTitle("Address book");
				this.setSize(830,520);
				this.setLocationRelativeTo(null);
				this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				
				this.setLayout(new BorderLayout());
							
				ContactWindow w = new ContactWindow(this);
				this.add(w, BorderLayout.WEST);				
				
				this.setVisible(true);
	}
	
	/**
	 * Add a new JPanel to the main window at the right of the window
	 * @param p, it is the panel that needs to be added (profile page, modify page, add page, etc..)
	 */
	public void setWindowProfile(JPanel p){		

		this.add(p, BorderLayout.CENTER);
		this.setVisible(true);	
		
	}
	
	/**
	 * Set the parameter of the window to the default parameters
	 */
	public void setLayoutNull(){
		
		this.getContentPane().removeAll();

		this.Init();
		this.getContentPane().repaint();

		
	}

	
	

	/**
	 * Method called to display the contact when selected by group or my name
	 * @param contactsList, it is the list of the contacts that need to be in the displayed list
	 * (only the contacts selected by the user according to what he wrote on the search field)
	 */
	
	public void setLayoutByGroup(ArrayList<Contact> contactsList){
		

		this.getContentPane().removeAll();
		this.setTitle("Address book");
		this.setSize(830,520);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			
		this.setLayout(new BorderLayout());
		ContactWindow w = new ContactWindow(this, contactsList);
		this.add(w, BorderLayout.WEST);

		this.setVisible(true);
		this.getContentPane().repaint();

		
	}
	
	
	public String getStaticSearch() {
		return staticSearch;
	}



	public void setStaticSearch(String staticSearch) {
		this.staticSearch = staticSearch;
	}



	public String getStaticWord() {
		return staticWord;
	}



	public void setStaticWord(String staticWord) {
		this.staticWord = staticWord;
	}

	
	
}
